<?php

namespace app\store\controller\setting;

use app\store\controller\BaseController;
use app\store\service\PaymentConfigService;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;

class ConfigController extends BaseController
{
    public function index()
    {

        $rst = Db::name('config')->where('store_id', session('store_id'))->select();
        $row = [];
        foreach($rst as $k => $v) {
            $row[$v['key']] = $v['value'];
        }

        $rstC = Db::name('commission_config')->where('store_id', session('store_id'))->select();
        $row1 = [];
        foreach($rstC as $k => $v) {
            $row1[$v['key']] = $v['value'];
        }
        $row = array_merge($row, $row1);
        return View::fetch('',['row' => $row]);
    }

    public function save()
    {
        $param = $this->request->post();
        foreach($param as $k => $v) {
            Db::name('config')->where('key', $k)->where('store_id', session('store_id'))->update(['value'=>$v]);
        }
        return json(['code' => 1, 'msg' => '保存成功!']);

    }

    public function saveFr(){
        $param = $this->request->post();
        foreach($param as $k => $v) {
            Db::name('commission_config')->where('key', $k)->where('store_id', session('store_id'))->update(['value'=>$v]);
        }
        return json(['code' => 1, 'msg' => '保存成功!']);
    }

}